package com.promis.party.ui.partywork.dailywork.assessment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.promis.party.R;
import com.promis.party.helper.ContextHelper;
import com.promis.widget.paging.OnPageRefreshListener;
import com.promis.widget.paging.OnPageScrollListener;
import com.promis.widget.paging.PageRefreshRecyclerView;
import com.promis.widget.recycler.RecyclerLayoutManagerHelper;

/**
 *
 */
public class AssessmentFragment extends Fragment {

    private ContextHelper contextHelper;

    private LinearLayout rootLayout;
    private PageRefreshRecyclerView pageRefreshRecyclerView;
    private RecyclerView rylvContainer;
    private AssessmentAdapter adaptPledge;
    public final static AssessmentFragment newInstance() {
        AssessmentFragment fragment = new AssessmentFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootLayout = (LinearLayout) inflater.inflate(R.layout.fragment_item_list, null, false);
        pageRefreshRecyclerView = rootLayout.findViewById(R.id.fragment_item_prrv_container);
        initData();
        initListener();
        return rootLayout;
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == Activity.RESULT_OK){
            if(requestCode == 206){
            }
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
//        outState.putSerializable("receiptTradeList", receiptTradeList);
//        outState.putSerializable("pageInfo", pageInfo);
    }

    private void initData() {
        contextHelper = new ContextHelper(getContext());
        rylvContainer = pageRefreshRecyclerView.getRecyclerView();
        RecyclerLayoutManagerHelper.buildVerticalLinearLayoutManager(getContext(), rylvContainer);
        adaptPledge = new AssessmentAdapter(getContext());
        rylvContainer.setAdapter(adaptPledge);
    }

    private void initListener() {
        pageRefreshRecyclerView.setOnPageScrollListener(new OnPageScrollListener() {
            @Override
            public void onLoadPageData() {
            }
        });
        pageRefreshRecyclerView.setOnRefreshListener(new OnPageRefreshListener() {
            @Override
            public void onRefresh() {
            }
        });
        adaptPledge.setOnItemClickListener(new AssessmentAdapter.OnItemClickListener() {
            @Override
            public void onClickComment(View view, int position) {
                Intent intent = new Intent(getContext(),AssessUserListActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

}
